home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / mint / filesy~1 / mfs609s.zoo / fsck / io.c < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-25  |  2.9 KB  |  129 lines

  1. /* The functions read_blocks(start,count,buff) and write_blocks(), read/write
  2.  * 'count' 1K blocks from disk starting at block 'start' into the buffer
  3.  * pointed to by 'buff' . The function init_device(name,rw) initialises the 
  4.  * device 'name' so that read_blocks() and write_blocks() use it. Since this
  5.  * is called once initially, any other machine dependent initialisation can be
  6.  * put here, if it returns non-zero then the operation failed. If 'rw' is not
  7.  * zero, write access is sought also for this device. The function set_size is
  8.  * used to tell the I/O routines the size of the filesystems being accessed,
  9.  * so any special arrangements can be made. If this function returns non-zero
  10.  * then the operation failed and the filesystem cannot be accessed.
  11.  */
  12.  
  13. #ifdef atarist
  14.  
  15. #include <stdio.h>
  16. #include <mintbind.h>
  17. #include "fs.h"
  18. #include "global.h"
  19. #include "proto.h"
  20.  
  21. int _device,_write_ok,shift;
  22.  
  23. void read_blocks(start,count,buff)
  24. long start;
  25. unsigned count;
  26. void *buff;
  27. {
  28.  
  29.     long ret;
  30.     ret=block_rwabs(0,buff,count,start,&hdinf);
  31.     if(ret) printf("Rwabs read returned %ld\n",ret);
  32. }
  33.  
  34. void write_blocks(start,count,buff)
  35. long start;
  36. unsigned count;
  37. void *buff;
  38. {
  39.     long ret;
  40. if(start==0){
  41.  printf("Illegal Write\n");
  42. return;
  43. }
  44.     if(!_write_ok)
  45.     {
  46.         printf("Internal error : Illegal write\n");
  47.         printf("Start %ld Count %d\n",(long)start,count);
  48.         return;
  49.     }
  50.     modified=1;
  51.     ret=block_rwabs(1,buff,count,start,&hdinf);
  52.     if(ret) printf("Rwabs write returned %ld\n",ret);
  53. }
  54.  
  55. int init_device(name,rw)
  56. char *name;
  57. int rw;
  58. {
  59.     long err;
  60.     if(name[1]==':')
  61.     {
  62.         struct 
  63.         {
  64.             long start;
  65.             long finish;
  66.             char shadow;
  67.             char scsiz;
  68.         } pp;
  69.         _device=(name[0]-'A') & ~32;
  70.         if( (_device < 0) || (_device > 32) ) return 1;
  71.         if( !Dcntl(0x109,name,&pp) && pp.start!=-1)
  72.         /* Is this a physical partition ? */
  73.         {
  74.             long tstack;
  75.             hdinf.start=pp.start;
  76.             hdinf.size=pp.finish-hdinf.start+1;
  77.             hdinf.scsiz=pp.scsiz;
  78.             hdinf.drive=_device;
  79.             hdinf.major = pp.shadow;
  80.             (void)Getbpb(_device);     /* Satisfy disk changes */
  81.             hdinf.rwmode = RW_PHYS;
  82.             tstack=Super(0l);
  83.             if(init_icd()==2)
  84.             {
  85.                 Super(tstack);
  86.                 fprintf(stderr,"Can't patch ICD bug\n");
  87.                 return 1;
  88.             }
  89.             Super(tstack);
  90.             if(hdinf.start > 0xfff0)
  91.             {
  92.                 if(no_plrecno(hdinf.major)) return 1;
  93.                 hdinf.rwmode |= RW_LRECNO;
  94.             }
  95.         }
  96.         else if( (err=get_hddinf(_device,&hdinf,0)) ) 
  97.         {
  98.             fprintf(stderr,"Drive %s %s\n",name,hdd_err[err]);
  99.             return 1;
  100.         }
  101.         if(rw) _write_ok=1;
  102.  
  103.         Dcntl(0x10b,name,1);    /* Suspend update */
  104.         /* Sync the filesytem and lock the device */
  105.         if(Dcntl(0x101,name,0) || Dlock(1,_device) )
  106.         {
  107.             close_device();
  108.             return 1;
  109.         }
  110.         return 0;
  111.     }
  112.     return 1;
  113. }
  114.  
  115. void close_device()
  116. {
  117.     extern char *drvnam;
  118.     (void) Dlock(0,_device);    /* Unlock drive */
  119.     Dcntl(0x10b,drvnam,2);        /* Restart update */
  120. }
  121.  
  122. int set_size(nblocks)
  123. long nblocks;
  124. {
  125.     return set_lrecno(&hdinf,nblocks);
  126. }
  127.  
  128. #endif
  129.